<?php

class PageInfo
{
    public $id;

    public $path;
    public $tplFile;
    public $phpFile;
    public $class;

    public $canonical;
    public $ref;
    public $name;
    public $title;
    public $icon;
    public $keywords;
    public $description;
    public $javascripts = array();
    public $stylesheets = array();
    public $seoBlock;
    public $secure;
    public $sslRequired;

    public $parent = null;
    public $children = array();
    public $quickLinks = array();

    public $search = true;
    public $comments = false;
    public $link = true;
    public $topMenuExpand = true;

    public $top = true;
    public $left = false;
    public $right = true;
    public $bottom = true;
    public $featured_customers = false;

    public $sitemap = true;
    public $static = false;

    public $language = SiteLanguage::EN;

    public $themeID = DEFAULT_THEME_ID;

    public $useNginxCache;

    public $params = array();

    public $loginUrl = null;

    /**
     * Sets unspecified parameters by another page info instance.
     * @param PageInfo $pageInfo
     */
    public function Init( PageInfo &$pageInfo )
    {
        Util::SetIfNull( $this->path,           $pageInfo->path );
        Util::SetIfNull( $this->tplFile,        $pageInfo->tplFile );
        Util::SetIfNull( $this->phpFile,        $pageInfo->phpFile );
        Util::SetIfNull( $this->class,          $pageInfo->class );
        Util::SetIfNull( $this->name,           $pageInfo->name );
        Util::SetIfNull( $this->title,          $pageInfo->title );
        Util::SetIfNull( $this->keywords,       $pageInfo->keywords );
        Util::SetIfNull( $this->description,    $pageInfo->description );
        Util::SetIfNull( $this->icon,           $pageInfo->icon );
        Util::SetIfNull( $this->params,         $pageInfo->params );

        Util::SetIfNull( $this->themeID,        $pageInfo->themeID );

        Util::SetIfNull($this->canonical,       $pageInfo->canonical);
        Util::SetIfEmpty($this->language, $pageInfo->language);
        Util::SetIfEmpty($this->ref, $pageInfo->ref);
        Util::SetIfEmpty( $this->static,        $pageInfo->static );
        Util::SetIfNullOrEmptyArray( $this->javascripts,    $pageInfo->javascripts );
        Util::SetIfNullOrEmptyArray( $this->stylesheets,    $pageInfo->stylesheets );
        Util::SetIfNull( $this->secure,         $pageInfo->secure );
        Util::SetIfNull( $this->sslRequired,    $pageInfo->sslRequired );
        Util::SetIfNullOrEmptyArray( $this->quickLinks,     $pageInfo->quickLinks );

        $this->top    = $pageInfo->top;
        $this->left   = $pageInfo->left;
        $this->right  = $pageInfo->right;
        $this->bottom = $pageInfo->bottom;
        $this->topMenuExpand = $pageInfo->topMenuExpand;

        $this->featured_customers = $pageInfo->featured_customers;
        Util::SetIfNull( $this->seoBlock,       $pageInfo->seoBlock );
        Util::SetIfNull( $this->name,           $pageInfo->name );

        Util::SetIfNull( $this->useNginxCache,   $pageInfo->useNginxCache );

        Util::SetIfNull( $this->loginUrl,        $pageInfo->loginUrl );
    }

    /**
     * Sets page settings specified in page_tree settings file by original page info.
     * @param PageInfo $pageInfo
     */
    public function SetPageTreesSettings( PageInfo &$pageInfo )
    {
        $this->link    = $pageInfo->link;
        $this->sitemap = $pageInfo->sitemap;
        $this->parent  = $pageInfo->parent;
        $this->children  = $pageInfo->children;
    }

    /**
     * Returns original page id without language additions.
     * @return string
     */
    public function GetOriginalPageId()
    {
        $pageId = $this->id;
        if ( $this->language != SiteLanguage::EN )
        {
            $pageId = str_ireplace( $this->language, "", $this->id );
        }
        return $pageId;
    }

    /**
     * Returns page id for translated page by original page id.
     * @param string $pageId
     * @param string $language
     * @return string
     */
    public static function GetTranslatedPageId( $pageId, $language )
    {
        return $pageId . $language;
    }

    public function IsTranslatedPage()
    {
        return $this->language != SiteLanguage::EN;
    }

    public function GetUrl($params = null)
    {
        if ( UrlHelper::IsPathAbsolute($this->path) )
        {
            return $this->path;
        }

        $url = ($this->sslRequired ? 'https' : 'http') . '://' . Request::GetHost() . '/' . $this->path;
        if ( !empty($params) && is_array($params) )
        {
            $url = UrlHelper::AddUrlParams($url, $params);
        }

        return $url;
    }
}

?>